package cn.zhj.service.impl;

import cn.zhj.domain.Teacher;
import cn.zhj.mapper.TeacherMapper;
import cn.zhj.query.TeacherQuery;
import cn.zhj.service.ITeacherService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service
@Transactional(readOnly = true, propagation = Propagation.SUPPORTS)
@Slf4j
public class TeacherServiceImpl implements ITeacherService {
    @Autowired
    private TeacherMapper teacherMapper;// idea没识别，不影响
    @Override
    public Teacher findOne(int id) {
//        employeeMapper.findOne(id);
        return teacherMapper.findOne(id);
    }

    @Override
    public List<Teacher> findAll() {
        return teacherMapper.findAll();
    }

    @Transactional
    @Override
    public void insert(Teacher teacher) {
        teacherMapper.insert(teacher);
    }

    @Transactional
    @Override
    public void delete(int id) {
        teacherMapper.delete(id);
    }

    @Transactional
    @Override
    public void update(Teacher teacher) {
        teacherMapper.update(teacher);
    }

    @Override
    public Map<String, Object> queryPage(TeacherQuery teacherQuery) {
        Map<String, Object> map = new HashMap<>();
        Integer totals = teacherMapper.getCount(teacherQuery);
        List<Teacher> data = teacherMapper.getData(teacherQuery);
        map.put("totals",totals);
        map.put("data",data);
        return map;
    }

    @Transactional
    @Override
    public void patchDeL(Integer[] ids) {
        teacherMapper.patchDeL(ids);
    }
}
